package Thread.Safe;

/**
 * synchronized修饰讲台方法
 */
public class synchronize_static {

    public static void main(String[] args) {
      Counter counter1=new Counter();
      Counter counter2=new Counter();
      Counter counter3=new Counter();
      Thread t1=new Thread(()->{
         counter1.increase1();
      },"t1线程~~");
      Thread t2=new Thread(()->{
         counter2.increase1();
      },"t2线程~~");
      Thread t3=new Thread(()->{
         counter3.increase1();
      },"t3线程~~");
      t1.start();
      t2.start();
      t3.start();
    }

    private static class Counter {
        synchronized static void increase1() {
            while (true) {
                System.out.println(Thread.currentThread().getName() + "获取到锁~~");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}